#include "base/conf.h"
#include <stdio.h>
#include <iostream>
#include <yaml-cpp/yaml.h>

using namespace std;

namespace xrtc
{
    int load_general_conf(const char *filename, GeneralConf *conf)
    {
        if (!filename || !conf)
        {
            fprintf(stderr, "filename or conf is nullptr\n");
            return -1;
        }

        YAML::Node config = YAML::LoadFile(filename);
        try
        {
            conf->log_dir = config["log"]["log_dir"].as<string>();
            conf->log_name = config["log"]["log_name"].as<string>();
            conf->log_level = config["log"]["log_level"].as<string>();
            conf->log_to_stderr = config["log"]["log_to_stderr"].as<bool>();
        }
        catch (YAML::Exception e)
        {
            fprintf(stderr, "catch a YAML::Exception, line: %d, column: %d"
                            ", error:%s\n",
                    e.mark.line + 1, e.mark.column + 1, e.msg.c_str());
            return -1;
        }

        return 0;
    }
} // namespace xrtc